Attribute VB_Name = "modFlashTaskbar"
Option Explicit

''Usage:
'Private Sub cmdFlashwin_Click(Index As Integer)
'    Select Case Index
'        Case 0
'            FlashTaskbarWin Me.hwnd, True
'        Case 1
'            FlashTaskbarWin Me.hwnd, False
'    End Select
'End Sub

Private Const FLASHW_STOP = 0 'Stop flashing. The system restores the window to its original state.
Private Const FLASHW_CAPTION = &H1 'Flash the window caption.
Private Const FLASHW_TRAY = &H2 'Flash the taskbar button.
Private Const FLASHW_ALL = (FLASHW_CAPTION Or FLASHW_TRAY) 'Flash both the window caption and taskbar button. This is equivalent to setting the FLASHW_CAPTION Or FLASHW_TRAY flags.
Private Const FLASHW_TIMER = &H4 'Flash continuously, until the FLASHW_STOP flag is set.
Private Const FLASHW_TIMERNOFG = &HC 'Flash continuously until the window comes to the foreground.
 
Private Type FLASHWINFO
    cbSize As Long
    hwnd As Long
    dwFlags As Long
    uCount As Long
    dwTimeout As Long
End Type
 
Private Declare Function FlashWindowEx Lib "user32" (pfwi As FLASHWINFO) As Boolean
 
Public Sub FlashTaskbarWin(hWndFlashWin As Long, Optional bEnable As Boolean = True)
    Dim FlashInfo As FLASHWINFO
    If bEnable Then
        With FlashInfo
            .cbSize = Len(FlashInfo)
            .dwFlags = FLASHW_ALL Or FLASHW_TIMER
            'Specifies the rate, in milliseconds, at which the window will be flashed.
            'If dwTimeout is zero, the function uses the default cursor blink rate.
            .dwTimeout = 0
            .hwnd = hWndFlashWin
            .uCount = 0
        End With
        FlashWindowEx FlashInfo
    Else
        With FlashInfo
            .cbSize = Len(FlashInfo)
            .dwFlags = FLASHW_STOP
            .hwnd = hWndFlashWin
        End With
        FlashWindowEx FlashInfo
    End If
End Sub
